package mysql

import "gorm.io/gorm"

type UserInfo struct {
	gorm.Model
	PhoneNum      string `gorm:"type:varchar(30);not null;comment:'手机号'"`
	Pwd           string `gorm:"type:varchar(32);not null;comment:'密码'"`
	NikeName      string `gorm:"type:varchar(50);not null;comment:'昵称'"`
	AvatarLink    string `gorm:"type:varchar(500);comment:'头像'"`
	AccountStatus int    `gorm:"type:int(11);default:0;comment:'账号状态'"`
	FollowNum     int    `gorm:"type:int(11);default:0;comment:'关注数'"`
	FansNum       int    `gorm:"type:int(11);default:0;comment:'粉丝数'"`
}

func (i *UserInfo) FindUserByMobile(db *gorm.DB, mobile string) error {
	return db.Debug().Where("phone_num=?", mobile).Find(i).Error
}

func (i *UserInfo) Register(db *gorm.DB) error {
	return db.Debug().Create(i).Error
}

func (i *UserInfo) UserUpdate(db *gorm.DB) error {
	return db.Debug().Updates(i).Error
}

func (i *UserInfo) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(i).Error
}
